<template>
	<view>
		<!-- <uni-nav-bar left-icon="back" left-text="" right-text="" title='账户登录'></uni-nav-bar> -->

		<image src="../../../static/images/error.jpg" mode=""></image>
		<form @submit="formSubmit" @reset="formReset">
			<input name='name' value="" class="uni-input" focus placeholder="请输入账号" />
			<view class="password">
				<input value="" name='password' class="uni-input" :password="showPassword" type="text" placeholder="登录密码" />
				<uni-icons @click='isshow' v-if="eyeshow" class='icon' color="#777" type="eye" size="20">
				</uni-icons>
				<uni-icons @click='isshow' v-else class='icon' color="#777" type="email" size="20"></uni-icons>
			</view>
			<view class="uni-btn-v">
				<button :class="str=='ok'?'act':''" form-type="submit">{{str=='ok'?'':'登录'}}</button>
			</view>
		</form>
		<view class="tool">
			<view class="" @click="toeditpassword">忘记密码</view>
			<view class=""> | </view>
			<view class="" @click="tologin">注册账户</view>
		</view>
	</view>
</template>

<script>
	import {
		register,
		updateMemberInfo,
		updatePassword,
		doLogin,
		uploadAvatar,
		getMemberInfo
	} from '../../../api/my/login/login.js'
	export default {
		data() {
			return {
				showPassword: true,
				eyeshow: true,
				ischeck: 'false',
				str: '',
			};
		},
		methods: {
			// 切换密码看的见不
			isshow() {
				if (this.eyeshow) {
					this.eyeshow = false;
					this.showPassword = false
				} else {
					this.eyeshow = true;
					this.showPassword = true
				}
			},
			//到修改密码界面
			toeditpassword() {
				uni.navigateTo({
					url: '../login/editpassword/editpassword',
				});
			},
			// 到登录页面
			tologin() {
				uni.navigateTo({
					url: '../login/login',
				});
			},
			// 登录
			formSubmit(e) {
				console.log(e.detail.value);
				var value = e.detail.value

				doLogin({
					"password": value.password,
					"username": value.name
				}).then(res => {
					console.log(res);
					if (res.success) {
						this.str = 'ok'
						uni.showToast({
							title: "登录成功"
						})
						uni.setStorageSync('token', res.data.token)
						
						getMemberInfo().then(res => {
							console.log(res);
							uni.setStorageSync('userinfo', res.data.userInfo)
							this.nickname = res.data.userInfo.nickname;
							this.username = res.data.userInfo.username;
							this.imageurl = res.data.userInfo.icon;
						})
						
						
						setTimeout(function() {
							uni.switchTab({
								url: '../my',
							});
						}, 1700)
					}
				})

				// uni.request({
				// 	url: 'http://localhost/lejuClient/login/doLogin',
				// 	method: "POST",
				// 	data: {

				// 	},
				// 	success(res) {

				// 	}
				// })
				// doLogin({
				// 	'password': value.password,
				// 	'username': value.name
				// }).then(res => {
				// 	console.log(res);
				// })
			}
		}
	}
</script>

<style lang="scss">
	.tool {
		display: flex;
		justify-content: space-between;
		width: 300rpx;
		margin: 0 auto;
		font-size: 28rpx;
	}

	image {
		width: 160rpx;
		height: 160rpx;
		border-radius: 50%;
		display: block;
		margin: 80rpx auto;
	}

	.password {
		position: relative;
		width: 610rpx;
		margin: 0 auto;

		.icon {
			position: absolute;
			top: 28rpx;
			right: 40rpx;
			z-index: 999;
			width: 32rpx;
			height: 32rpx;
			color: #666;

		}
	}

	input {
		width: 610rpx;
		height: 100rpx;
		padding: 0rpx 40rpx;
		border-radius: 50rpx;
		margin: 0 auto;
		box-sizing: border-box;
		margin-bottom: 40rpx;
		box-shadow: 0 0 30px 0 rgba(43, 86, 112, .1);
	}

	.code {
		position: relative;
		width: 610rpx;
		margin: 0 auto;
		box-sizing: border-box;

		text {
			position: absolute;
			font-size: 24rpx;
			top: 34rpx;
			box-sizing: border-box;
			right: 35rpx;
			z-index: 999;
			height: 32rpx;
			color: #666;
		}
	}

	button {

		width: 600rpx;
		height: 100rpx;
		margin: 80rpx auto;
		border-radius: 50rpx;
		color: white;
		box-sizing: border-box;
		line-height: 100rpx;
		background-color: #354E44;
		font-size: 28rpx;
		margin-bottom: 40rpx;
		transition: .6s;
	}

	.act {
		width: 100rpx;
	}

	.radio {
		width: 200rpx;
		box-sizing: border-box;
		margin-left: 275rpx;
		font-size: 28rpx;
	}
</style>
